package com.automobile.backstage.controller;

import com.automobile.backstage.domain.MakeApp;
import com.automobile.backstage.service.MakeAppService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("/makeApp")
public class MakeAppController {
	
	@Autowired
	private MakeAppService makeAppService;
	
	@RequestMapping("/save")
	public @ResponseBody int save(@RequestBody MakeApp makeApp) {
		System.out.println("make:"+makeApp);
		if(makeApp==null) {
			return 0;
		}
		makeAppService.save(makeApp);
		return 1;
	}

	@RequestMapping("/findAll")
    public @ResponseBody PageInfo findAll(@RequestParam(value = "page",required = true,defaultValue = "1")Integer page,
                                          @RequestParam(value = "size",required = true,defaultValue = "10")Integer size) throws Exception {
        List<MakeApp> makeapps = makeAppService.findAll(page, size);
        PageInfo pageInfo = new PageInfo(makeapps);
        return pageInfo;
    }

    @RequestMapping("/del")
    public @ResponseBody int del(@RequestBody List<Integer> ids) throws Exception {
        makeAppService.del(ids);
	    return 1;
    }

    @RequestMapping("/findMakeAppById")
    public @ResponseBody MakeApp findMakeAppById(@RequestBody int id) throws Exception {
        System.out.println(id);
        MakeApp makeapps = makeAppService.findMakeAppById(id);
        return makeapps;
    }

}
